package srv

import (
	"context"
	"driver_certification_srv/internal/dao"
	"driver_certification_srv/pkg"
	pb "driver_certification_srv/proto"
	"errors"
)

type Server struct {
	pb.UnimplementedDriverServer
}

func (s *Server) DriverRegister(c context.Context, req *pb.DriverRegisterReq) (*pb.DriverRegisterResp, error) {
	d := dao.Driver{
		Username: req.Username,
		Password: pkg.Md5Pwd(req.Password),
	}
	id, message := d.DriverCreate()
	if message != "" {
		return &pb.DriverRegisterResp{Id: 0}, errors.New(message)
	}
	return &pb.DriverRegisterResp{Id: int64(id)}, nil
}
